import Vue from 'vue';
import VueRouter from 'vue-router';
// import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter);

const routes = [
  {
    path: '/HomePage',
    name: 'HomePage',
    component: () => import('../views/Home/HomePage.vue') //主页
  },
  {
    path: '/ScanView',
    name: 'ScanView',
    component: () => import('../views/Scan/ScanView.vue') //扫描条码页
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/User/LoginPage.vue') //登录页
  },
  {
    path: '/RawMaterialInfo',
    name: 'RawMaterialInfo',
    component: () => import('../views/RawMaterialInbound/RawMaterialInfo.vue') //原料入库
  },
  {
    path: '/MoveLocationInfo',
    name: 'MoveLocation',
    component: () => import('../views/MoveLocation/MoveLocation.vue') //移库
  },
  {
    path: '/ChangePassword',
    name: 'ChangePassword',
    component: () => import('../views/User/ChangePassword.vue') //修改密码
  },
  {
    path: '/ProductionInbound',
    name: 'ProductionInbound',
    component: () => import('../views/ProductionInbound/ProductionInbound.vue') //成品预收货
  },
  {
    path: '/ProductInboundConfirm',
    name: 'ProductInboundConfirm',
    component: () => import('../views/ProductInboundConfirm/ProductInboundConfirm.vue') //成品确认入库
  },
  {
    path: '/ProductOutbound',
    name: 'ProductOutbound',
    component: () => import('../views/ProductOutbound/ProductOutbound.vue') //成品出库
  },
  {
    path: '/SalesOutbound',
    name: 'SalesOutbound',
    component: () => import('../views/SalesOutbound/SalesOutbound.vue') //成品出库
  },
  {
    path: '/ProductInboundInfo',
    name: 'ProductInboundInfo',
    component: () => import('../views/ProductInboundConfirm/ProductInboundInfo.vue') //成品确认入库信息
  },
  {
    path: '/CarNoListInfo',
    name: 'CarNoListInfo',
    component: () => import('../views/ToneSlotsRecycle/CarNoListInfo.vue') //车牌号清单信息
  },
  {
    path: '/ToneSlotsRecycle',
    name: 'ToneSlotsRecycle',
    component: () => import('../views/ToneSlotsRecycle/ToneSlotsRecycle.vue') //吨槽回收
  },
  {
    path: '/ProductionFeed',
    name: 'ProductionFeed',
    component: () => import('../views/ProductionFeed/ProductionFeed.vue') //吨槽回收
  },
  {
    path: '/ToneSlotsSend',
    name: 'ToneSlotsSend',
    component: () => import('../views/ToneSlotsSend/ToneSlotsSend.vue') //吨槽发出
  },
  {
    path: '/AdjustToneSlots',
    name: 'AdjustToneSlots',
    component: () => import('../views/AdjustToneSlots/AdjustToneSlots.vue')//吨槽回收
  },
  {
    path: '/LocationCheck',
    name: 'LocationCheck',
    component: () => import('../views/LocationCheck/LocationCheck.vue')//吨槽回收
  },

  {
    path: '/',
    redirect: '/HomePage'
  }
];

const router = new VueRouter({
  routes
});

export default router;

router.beforeEach((to, from, next) => {
  //to到哪儿  from从哪儿离开  next跳转 为空就是放行
  if (to.path === '/Login') {
    //如果跳转为登录，就放行
    next();
  } else {
    //取出localStorage判断
    let token = localStorage.getItem('token');
    if (token == null || token === '') {
      console.log('请先登录');
      next({
        name: 'Login'
      });
    } else {
      next();
    }
  }
});
